#
#    Copyright (C) 2016 Francisco Javier Parra <franparpe@openmailbox.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem


from PyQt5 import QtCore

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s


class Recopilation(QTableWidget):
    """This table contains a recopilation


    """
    def __init__(self, parent):
        super(Recopilation, self).__init__(parent)
        
    def unilateral_flat(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Cam with a flat-faced follower with translating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        follInclinationHead = _fromUtf8("Angle inclination:")
        follInclination = str(round(theCam.beta, 3)) + " [º]"

        excentricityHead = _fromUtf8("Follower's excentricity")
        excentricity = str(round(theCam.excentricity, 3)) + " [mm]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        follInclinationHead = QTableWidgetItem(follInclinationHead)
        follInclination = QTableWidgetItem(follInclination)
        excentricityHead = QTableWidgetItem(excentricityHead)
        excentricity = QTableWidgetItem(excentricity)

        self.setRowCount(5)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, follInclinationHead)
        self.setItem(3, 1, follInclination)
        self.setItem(4, 0, excentricityHead)
        self.setItem(4, 1, excentricity)

    def unilateral_circular(self, theCam):
        self.clear()        
        mechanism = _fromUtf8("Cam with a circular-faced follower with translating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        follRadiusHead = _fromUtf8("Radius of the follower's roller:")
        follRadius = str(round(theCam.followerRadius, 3)) + " [mm]"

        excentricityHead = _fromUtf8("Follower's excentricity")
        excentricity = str(round(theCam.excentricity, 3)) + " [mm]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        follRadiusHead = QTableWidgetItem(follRadiusHead)
        follRadius = QTableWidgetItem(follRadius)
        excentricityHead = QTableWidgetItem(excentricityHead)
        excentricity = QTableWidgetItem(excentricity)

        self.setRowCount(5)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, follRadiusHead)
        self.setItem(3, 1, follRadius)
        self.setItem(4, 0, excentricityHead)
        self.setItem(4, 1, excentricity)

    def unilateral_flat_angular(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Cam with a flat-faced follower with rotating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        l1Head = _fromUtf8("Distance between rotation centers (l1):")
        l1 = str(round(theCam.l1, 3)) + " [mm]"

        l2Head = _fromUtf8("Follower arm's length (l2):")
        l2 = str(round(theCam.l2, 3)) + " [mm]"

        gammaHead = _fromUtf8("Initial follower inclination:")
        gamma = str(round(theCam.angleGamma, 3)) + " [º]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        l1Head = QTableWidgetItem(l1Head)
        l1 = QTableWidgetItem(l1)
        l2Head = QTableWidgetItem(l2Head)
        l2 = QTableWidgetItem(l2)
        gammaHead = QTableWidgetItem(gammaHead)
        gamma = QTableWidgetItem(gamma)

        self.setRowCount(6)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, l1Head)
        self.setItem(3, 1, l1)
        self.setItem(4, 0, l2Head)
        self.setItem(4, 1, l2)
        self.setItem(5, 0, gammaHead)
        self.setItem(5, 1, gamma)

    def unilateral_circular_angular(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Cam with a circular-faced follower with translating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        followerRadHead = _fromUtf8("Follower's face radius:")
        followerRad = str(round(theCam.followerRadius, 3)) + " [mm]"

        l1Head = _fromUtf8("Distance between rotation centers (l1):")
        l1 = str(round(theCam.l1, 3)) + " [mm]"

        l2Head = _fromUtf8("Arm length to roller (l3):")
        l2 = str(round(theCam.l2, 3)) + " [mm]"

        gammaHead = _fromUtf8("Initial follower inclination:")
        gamma = str(round(theCam.angleGamma, 3)) + " [º]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        followerRadHead = QTableWidgetItem(followerRadHead)
        followerRad = QTableWidgetItem(followerRad)
        l1Head = QTableWidgetItem(l1Head)
        l1 = QTableWidgetItem(l1)
        l2Head = QTableWidgetItem(l2Head)
        l2 = QTableWidgetItem(l2)
        gammaHead = QTableWidgetItem(gammaHead)
        gamma = QTableWidgetItem(gamma)

        self.setRowCount(7)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, followerRadHead)
        self.setItem(3, 1, followerRad)
        self.setItem(4, 0, l1Head)
        self.setItem(4, 1, l1)
        self.setItem(5, 0, l2Head)
        self.setItem(5, 1, l2)
        self.setItem(6, 0, gammaHead)
        self.setItem(6, 1, gamma)

    def bilateral_flat_follower(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Conjugate cam with a flat-faced follower with translating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        follInclinationHead = _fromUtf8("Angle inclination:")
        follInclination = str(round(theCam.beta, 3)) + " [º]"

        excentricityHead = _fromUtf8("Follower's excentricity")
        excentricity = str(round(theCam.excentricity, 3)) + " [mm]"

        separationHead = _fromUtf8("Separation between followers:")
        separation = str(round(theCam.separation, 3)) + " [mm]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        follInclinationHead = QTableWidgetItem(follInclinationHead)
        follInclination = QTableWidgetItem(follInclination)
        excentricityHead = QTableWidgetItem(excentricityHead)
        excentricity = QTableWidgetItem(excentricity)
        separationHead = QTableWidgetItem(separationHead)
        separation = QTableWidgetItem(separation)

        self.setRowCount(6)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, follInclinationHead)
        self.setItem(3, 1, follInclination)
        self.setItem(4, 0, excentricityHead)
        self.setItem(4, 1, excentricity)
        self.setItem(5, 0, separationHead)
        self.setItem(5, 1, separation)

    def bilateral_circular(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Conjugate cam with a circular-faced follower with translating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        follRadiusHead = _fromUtf8("Radius of the follower's roller:")
        follRadius = str(round(theCam.beta, 3)) + " [mm]"

        excentricityHead = _fromUtf8("Follower's excentricity")
        excentricity = str(round(theCam.excentricity, 3)) + " [mm]"

        separationHead = _fromUtf8("Separation between followers:")
        separation = str(round(theCam.separation, 3)) + " [mm]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        follRadiusHead = QTableWidgetItem(follRadiusHead)
        follRadius = QTableWidgetItem(follRadius)
        excentricityHead = QTableWidgetItem(excentricityHead)
        excentricity = QTableWidgetItem(excentricity)
        separationHead = QTableWidgetItem(separationHead)
        separation = QTableWidgetItem(separation)

        self.setRowCount(6)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, follRadiusHead)
        self.setItem(3, 1, follRadius)
        self.setItem(4, 0, excentricityHead)
        self.setItem(4, 1, excentricity)
        self.setItem(5, 0, separationHead)
        self.setItem(5, 1, separation)

    def bilateral_flat_angular(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Cam with a flat-faced follower with rotating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        l1Head = _fromUtf8("Distance between rotation centers (l1):")
        l1 = str(round(theCam.l1, 3)) + " [mm]"

        l2Head = _fromUtf8("Follower arm's length (l2):")
        l2 = str(round(theCam.l2, 3)) + " [mm]"

        gammaHead = _fromUtf8("Initial follower inclination:")
        gamma = str(round(theCam.gamma1, 3)) + " [º]"

        separationHead = _fromUtf8("Aperture angle between follower's amrs:")
        separation = str(round(theCam.beta, 3)) + " [º]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        l1Head = QTableWidgetItem(l1Head)
        l1 = QTableWidgetItem(l1)
        l2Head = QTableWidgetItem(l2Head)
        l2 = QTableWidgetItem(l2)
        gammaHead = QTableWidgetItem(gammaHead)
        gamma = QTableWidgetItem(gamma)
        separationHead = QTableWidgetItem(separationHead)
        separation = QTableWidgetItem(separation)

        self.setRowCount(6)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, l1Head)
        self.setItem(3, 1, l1)
        self.setItem(4, 0, l2Head)
        self.setItem(4, 1, l2)
        self.setItem(5, 0, gammaHead)
        self.setItem(5, 1, gamma)
        self.setItem(6, 0, separationHead)
        self.setItem(6, 1, separation)

    def bilateral_circular_angular(self, theCam):
        self.clear()
        mechanism = _fromUtf8("Cam with a circular-faced follower with translating movement")
        clockHead = _fromUtf8("Direction of rotation:")
        clock = _fromUtf8("counter-clock wise")

        baseRadiusHead = _fromUtf8("Base Radius:")
        baseRadius = str(round(theCam.rb, 3)) + " [mm]"

        followerRadHead = _fromUtf8("Follower's face radius:")
        followerRad = str(round(theCam.rb, 3)) + " [mm]"

        l1Head = _fromUtf8("Distance between rotation centers (l1):")
        l1 = str(round(theCam.l1, 3)) + " [mm]"

        l2Head = _fromUtf8("Arm length to roller (l3):")
        l2 = str(round(theCam.l3sup, 3)) + " [mm]"

        gammaHead = _fromUtf8("Initial follower inclination:")
        gamma = str(round(theCam.gamma1, 3)) + " [º]"

        separationHead = _fromUtf8("Aperture angle between follower's amrs:")
        separation = str(round(theCam.beta, 3)) + " [º]"

        mechanism = QTableWidgetItem(mechanism)
        clockHead = QTableWidgetItem(clockHead)
        clock = QTableWidgetItem(clock)
        baseRadiusHead = QTableWidgetItem(baseRadiusHead)
        baseRadius = QTableWidgetItem(baseRadius)
        followerRad = QTableWidgetItem(followerRad)
        followerRadHead = QTableWidgetItem(followerRadHead)
        l1Head = QTableWidgetItem(l1Head)
        l1 = QTableWidgetItem(l1)
        l2Head = QTableWidgetItem(l2Head)
        l2 = QTableWidgetItem(l2)
        gammaHead = QTableWidgetItem(gammaHead)
        gamma = QTableWidgetItem(gamma)
        separation = QTableWidgetItem(separation)
        separationHead = QTableWidgetItem(separationHead)

        self.setRowCount(8)
        self.setColumnCount(2)

        self.setItem(0, 0, mechanism)
        self.setItem(1, 0, clockHead)
        self.setItem(1, 1, clock)
        self.setItem(2, 0, baseRadiusHead)
        self.setItem(2, 1, baseRadius)
        self.setItem(3, 0, followerRadHead)
        self.setItem(3, 1, followerRad)
        self.setItem(4, 0, l1Head)
        self.setItem(4, 1, l1)
        self.setItem(5, 0, l2Head)
        self.setItem(5, 1, l2)
        self.setItem(6, 0, gammaHead)
        self.setItem(6, 1, gamma)
        self.setItem(7, 0, separationHead)
        self.setItem(7, 1, separation)
